﻿using System.IO.Ports;
namespace EMSNet.Service;
/// <summary>
/// 设备的配置类，包含连接信息、超时设置和Modbus操作的相关参数。
/// </summary>
/// 
[Tenant("1300000000003")]
[SugarTable("emsDeviceConfig", "设备配置")]
public class DeviceConfigEntity: EntityBase
{
    /// <summary>
    /// 租户Id
    /// </summary>
    [SugarColumn(ColumnName = "TenantId", ColumnDescription = "租户Id")]
    public virtual long? TenantId { get; set; }

    /// <summary>
    /// 创建者部门Id
    /// </summary>
    [SugarColumn(ColumnName = "CreateOrgId", ColumnDescription = "创建者部门Id")]
    public virtual long? CreateOrgId { get; set; }

    /// <summary>
    /// 创建者部门名称
    /// </summary>
    [SugarColumn(ColumnName = "CreateOrgName", ColumnDescription = "创建者部门名称", Length = 64)]
    public virtual string? CreateOrgName { get; set; }
    /// <summary>
    /// 设备的唯一标识符
    /// </summary>
    [SugarColumn(ColumnName = "DeviceId", ColumnDescription = "设备的唯一标识符", Length = 64)]
    public string? DeviceId { get; set; }

    /// <summary>
    /// 协议类型，支持 "TCP" 或 "RTU"
    /// </summary>
    [SugarColumn(ColumnName = "Protocol", ColumnDescription = "协议类型", Length = 64)]
    public string? Protocol { get; set; }

    /// <summary>
    /// 设备IP地址（仅TCP协议使用）
    /// </summary>
    /// 
    [SugarColumn(ColumnName = "Ip", ColumnDescription = "设备IP地址", Length = 64)]
    public string? Ip { get; set; }

    /// <summary>
    /// 设备端口（仅TCP协议使用）
    /// </summary>
    /// 
    [SugarColumn(ColumnName = "Port", ColumnDescription = "设备端口", Length = 64)]
    public int? Port { get; set; }

    /// <summary>
    /// 串口名称（仅RTU协议使用）
    /// </summary>
    /// 
    [SugarColumn(ColumnName = "PortName", ColumnDescription = "串口名称", Length = 64)]
    public string? PortName { get; set; }

    /// <summary>
    /// 波特率（仅RTU协议使用）
    /// </summary>
    /// 
    [SugarColumn(ColumnName = "BaudRate", ColumnDescription = "波特率", Length = 64)]
    public int? BaudRate { get; set; }

    /// <summary>
    /// 校验方式（仅RTU协议使用）
    /// </summary>
    /// 
    [SugarColumn(ColumnName = "Parity", ColumnDescription = "校验方式", Length = 64)]
    public Parity? Parity { get; set; }

    /// <summary>
    /// 数据位（仅RTU协议使用）
    /// </summary>
    /// 
    [SugarColumn(ColumnName = "DataBits", ColumnDescription = "数据位", Length = 64)]
    public int? DataBits { get; set; }

    /// <summary>
    /// 停止位（仅RTU协议使用）
    /// </summary>
    /// 
    [SugarColumn(ColumnName = "StopBits", ColumnDescription = "停止位", Length = 64)]
    public StopBits? StopBits { get; set; }

    /// <summary>
    /// Modbus设备的单元标识符
    /// </summary>
    public int? UnitId { get; set; }

    /// <summary>
    /// 读取的起始寄存器地址
    /// </summary>
    public int? StartAddress { get; set; }

    /// <summary>
    /// 要读取的寄存器数量
    /// </summary>
    public int? Count { get; set; }

    /// <summary>
    /// 数据轮询间隔（毫秒）
    /// </summary>
    public int? PollInterval { get; set; }

    /// <summary>
    /// 断线重连间隔（毫秒）
    /// </summary>
    public int? RetryInterval { get; set; }

    /// <summary>
    /// 读取超时（毫秒）
    /// </summary>
    public int? ReadTimeout { get; set; } = 5000; // 默认值

    /// <summary>
    /// 写入超时（毫秒）
    /// </summary>
    public int? WriteTimeout { get; set; } = 3000; // 默认值
}
